<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link rel="stylesheet" href="skin/base.css">
<link rel="stylesheet" href="skin/more.css">
<link rel="stylesheet" href="skin/btn.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body ontouchstart>
<div id="main" class="box-ver box">
  <div id="header">
  	<div class="title">
  		<span class="l icon back" ontouchstart="zy_touch('act')" onclick="uexWindow.close(-1);"></span>
		<span class="txt">设置关联账号</span>
	</div>
  </div>
  
  
  <div id="content">
    <div  class="more">
    	<div class="item">
      		<ul>
        		<li ontouchstart="zy_touch('down')" onclick="bind('sina')"><img src="skin/images/oauth/sina_tie.png" /><strong>新浪微博</strong><em id="sina"></em></li>
        		<li ontouchstart="zy_touch('down')" onclick="bind('qqweibo')"><img src="skin/images/oauth/qqweibo_tie.png" /><strong>腾讯微博</strong><em id="qqweibo"></em></li>
        		<!--
	  			<menu ontouchstart="zy_touch('down')" onclick="bind('qzone')"><img src="skin/images/oauth/qzone_tie.png" /><strong>QQ空间</strong><em id="qzone"></em></menu>
	  			-->
      		</ul>
	  	</div>
	  
      	<div class="btn">
        	<div class="button" onclick="uexWindow.close(-1);">完成</div>
      	</div>
    </div>
  </div>
</div>
</body>
<script>
    	zy_init();
		var stype = '';
		function ok(){
			if(localStorage['sina_connectid']){
				$$('sina').innerHTML = '已绑定';
			}else{
				$$('sina').innerHTML = '点击绑定';
			}

			if(localStorage['qqweibo_connectid']){
				$$('qqweibo').innerHTML = '已绑定';
			}else{
				$$('qqweibo').innerHTML = '点击绑定';
			}
			/*
			if(localStorage['qzone_connectid']){
				$$('qzone').innerHTML = '已绑定';
			}else{
				$$('qzone').innerHTML = '点击绑定';
			}
			*/
		}
		
		function bind(str){
			stype=str;
			if(stype=="qqweibo"){
				var wkey= l_connect['qqweibo'];
				var cburl=app_path+'bind.html';
				var url='https://open.t.qq.com/cgi-bin/oauth2/authorize?client_id='+wkey+'&response_type=token&redirect_uri='+encodeURIComponent(cburl)+'&wap=2';
				var e = $$("header");
				var y = e.offsetHeight;
				var s = window.getComputedStyle($$("content"),null);
				uexWindow.onOAuthInfo = onOAuth;
				uexWindow.openPopover('content','0',url,'',0,int(y),int(s.width),int(s.height),int(s.fontSize),'1');
			}else if(stype=="sina"){
				wkey= l_connect['sina'];
				var cburl=app_path+'bind.html';
				var url = 'https://api.weibo.com/oauth2/authorize?client_id='+wkey+'&response_type=token&redirect_uri='+encodeURIComponent(cburl)+'&display=mobile&forcelogin=true';
				var e = $$("header");
				var y = e.offsetHeight;
				var s = window.getComputedStyle($$("content"),null);
				uexWindow.onOAuthInfo = onOAuth;
				uexWindow.openPopover('content','0',url,'',0,int(y),int(s.width),int(s.height),int(s.fontSize),'1');
			}else if(stype=="qzone"){
				alert('qzone接口未开放');
			}
		}

		function onOAuth(winName, url){
			if (url.indexOf("expires_in") > 0) {
				uexWindow.toast(1, 5, '绑定中...', 0);
				var srt =url.split("#");
				var urls = app_path+'index.php?m=iappShare&c=index&a=bind&type='+stype+'&userid='+localStorage['u_id']+'&'+srt[1];
				uexXmlHttpMgr.open(1,'get',urls,"8000");
				uexXmlHttpMgr.send(1);
			}
		}
				
		window.uexOnload = function(type){
			if (!type) {
				uexXmlHttpMgr.onData = function(opId, status, data){
					uexXmlHttpMgr.close(opId);
					uexWindow.closeToast();
					uexWindow.closePopover('content');
					if (status == 1) {
						data = JSON.parse(data);
						if(data['success']=='OK'){
							localStorage[stype+'_connectid'] = data['data']['connectid'];
							uexWindow.toast("0","5","绑定成功~!",1000);
							ok();
						}else{
							uexWindow.toast("0","5",data['msg'],1000);
						}
					}else if(status==-1){						
						uexWindow.toast("0","5","绑定超时~",1000);
					}
				}
				ok();
			}
		}
    </script>
</html>